home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / f1ocx / vcform1.3 / VB4 / FORMAT2 / format2.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-09-15  |  28.2 KB  |  805 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Palette Maker"
  4.    ClientHeight    =   5070
  5.    ClientLeft      =   1155
  6.    ClientTop       =   1575
  7.    ClientWidth     =   9690
  8.    Height          =   5535
  9.    Icon            =   "format2.frx":0000
  10.    Left            =   1065
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5070
  13.    ScaleWidth      =   9690
  14.    Top             =   1200
  15.    Width           =   9870
  16.    Begin VB.Frame Frame3 
  17.       Caption         =   "  Generate Palette  "
  18.       Height          =   2655
  19.       Left            =   180
  20.       TabIndex        =   18
  21.       Top             =   2280
  22.       Width           =   4215
  23.       Begin VB.CommandButton cmdGenPalette 
  24.          Caption         =   "Generate"
  25.          Height          =   315
  26.          Left            =   60
  27.          TabIndex        =   34
  28.          Top             =   2160
  29.          Width           =   795
  30.       End
  31.       Begin Threed.SSPanel SSPanel3 
  32.          Height          =   1935
  33.          Left            =   3060
  34.          TabIndex        =   31
  35.          Top             =   540
  36.          Width           =   975
  37.          _Version        =   65536
  38.          _ExtentX        =   1720
  39.          _ExtentY        =   3413
  40.          _StockProps     =   15
  41.          BackColor       =   12632256
  42.          BevelOuter      =   1
  43.          Begin VB.OptionButton optBDelta 
  44.             Caption         =   "Bell"
  45.             Height          =   255
  46.             Index           =   3
  47.             Left            =   120
  48.             TabIndex        =   46
  49.             Top             =   1620
  50.             Width           =   795
  51.          End
  52.          Begin VB.OptionButton optBDelta 
  53.             Caption         =   "1/Log"
  54.             Height          =   255
  55.             Index           =   2
  56.             Left            =   120
  57.             TabIndex        =   45
  58.             Top             =   1380
  59.             Width           =   795
  60.          End
  61.          Begin VB.OptionButton optBDelta 
  62.             Caption         =   "Log"
  63.             Height          =   255
  64.             Index           =   1
  65.             Left            =   120
  66.             TabIndex        =   44
  67.             Top             =   1140
  68.             Width           =   795
  69.          End
  70.          Begin VB.OptionButton optBDelta 
  71.             Caption         =   "Linear"
  72.             Height          =   255
  73.             Index           =   0
  74.             Left            =   120
  75.             TabIndex        =   43
  76.             Top             =   900
  77.             Value           =   -1  'True
  78.             Width           =   795
  79.          End
  80.          Begin VB.TextBox txtFrom 
  81.             Alignment       =   1  'Right Justify
  82.             Height          =   285
  83.             Index           =   2
  84.             Left            =   240
  85.             TabIndex        =   33
  86.             Text            =   "0"
  87.             Top             =   120
  88.             Width           =   555
  89.          End
  90.          Begin VB.TextBox TxtTo 
  91.             Alignment       =   1  'Right Justify
  92.             Height          =   285
  93.             Index           =   2
  94.             Left            =   240
  95.             TabIndex        =   32
  96.             Text            =   "255"
  97.             Top             =   480
  98.             Width           =   555
  99.          End
  100.       End
  101.       Begin Threed.SSPanel SSPanel2 
  102.          Height          =   1935
  103.          Left            =   1980
  104.          TabIndex        =   28
  105.          Top             =   540
  106.          Width           =   975
  107.          _Version        =   65536
  108.          _ExtentX        =   1720
  109.          _ExtentY        =   3413
  110.          _StockProps     =   15
  111.          BackColor       =   12632256
  112.          BevelOuter      =   1
  113.          Begin VB.OptionButton optGDelta 
  114.             Caption         =   "Bell"
  115.             Height          =   255
  116.             Index           =   3
  117.             Left            =   120
  118.             TabIndex        =   42
  119.             Top             =   1620
  120.             Width           =   735
  121.          End
  122.          Begin VB.OptionButton optGDelta 
  123.             Caption         =   "1/Log"
  124.             Height          =   255
  125.             Index           =   2
  126.             Left            =   120
  127.             TabIndex        =   41
  128.             Top             =   1380
  129.             Width           =   735
  130.          End
  131.          Begin VB.OptionButton optGDelta 
  132.             Caption         =   "Log"
  133.             Height          =   255
  134.             Index           =   1
  135.             Left            =   120
  136.             TabIndex        =   40
  137.             Top             =   1140
  138.             Width           =   735
  139.          End
  140.          Begin VB.OptionButton optGDelta 
  141.             Caption         =   "Linear"
  142.             Height          =   255
  143.             Index           =   0
  144.             Left            =   120
  145.             TabIndex        =   39
  146.             Top             =   900
  147.             Value           =   -1  'True
  148.             Width           =   735
  149.          End
  150.          Begin VB.TextBox txtFrom 
  151.             Alignment       =   1  'Right Justify
  152.             Height          =   285
  153.             Index           =   1
  154.             Left            =   240
  155.             TabIndex        =   30
  156.             Text            =   "0"
  157.             Top             =   120
  158.             Width           =   555
  159.          End
  160.          Begin VB.TextBox TxtTo 
  161.             Alignment       =   1  'Right Justify
  162.             Height          =   285
  163.             Index           =   1
  164.             Left            =   240
  165.             TabIndex        =   29
  166.             Text            =   "255"
  167.             Top             =   480
  168.             Width           =   555
  169.          End
  170.       End
  171.       Begin Threed.SSPanel SSPanel1 
  172.          Height          =   1935
  173.          Left            =   900
  174.          TabIndex        =   25
  175.          Top             =   540
  176.          Width           =   975
  177.          _Version        =   65536
  178.          _ExtentX        =   1720
  179.          _ExtentY        =   3413
  180.          _StockProps     =   15
  181.          BackColor       =   12632256
  182.          BevelOuter      =   1
  183.          Begin VB.OptionButton optRDelta 
  184.             Caption         =   "Bell"
  185.             Height          =   255
  186.             Index           =   3
  187.             Left            =   120
  188.             TabIndex        =   38
  189.             Top             =   1620
  190.             Width           =   735
  191.          End
  192.          Begin VB.OptionButton optRDelta 
  193.             Caption         =   "1/Log"
  194.             Height          =   255
  195.             Index           =   2
  196.             Left            =   120
  197.             TabIndex        =   37
  198.             Top             =   1380
  199.             Width           =   735
  200.          End
  201.          Begin VB.OptionButton optRDelta 
  202.             Caption         =   "Log"
  203.             Height          =   255
  204.             Index           =   1
  205.             Left            =   120
  206.             TabIndex        =   36
  207.             Top             =   1140
  208.             Width           =   735
  209.          End
  210.          Begin VB.OptionButton optRDelta 
  211.             Caption         =   "Linear"
  212.             Height          =   255
  213.             Index           =   0
  214.             Left            =   120
  215.             TabIndex        =   35
  216.             Top             =   900
  217.             Value           =   -1  'True
  218.             Width           =   735
  219.          End
  220.          Begin VB.TextBox txtFrom 
  221.             Alignment       =   1  'Right Justify
  222.             Height          =   285
  223.             Index           =   0
  224.             Left            =   240
  225.             TabIndex        =   27
  226.             Text            =   "0"
  227.             Top             =   120
  228.             Width           =   555
  229.          End
  230.          Begin VB.TextBox TxtTo 
  231.             Alignment       =   1  'Right Justify
  232.             Height          =   285
  233.             Index           =   0
  234.             Left            =   240
  235.             TabIndex        =   26
  236.             Text            =   "255"
  237.             Top             =   480
  238.             Width           =   555
  239.          End
  240.       End
  241.       Begin VB.Label Label2 
  242.          Alignment       =   1  'Right Justify
  243.          Caption         =   "To:"
  244.          Height          =   195
  245.          Index           =   1
  246.          Left            =   300
  247.          TabIndex        =   23
  248.          Top             =   1080
  249.          Width           =   435
  250.       End
  251.       Begin VB.Label Label1 
  252.          Alignment       =   2  'Center
  253.          Caption         =   "Blue"
  254.          Height          =   195
  255.          Index           =   5
  256.          Left            =   3300
  257.          TabIndex        =   22
  258.          Top             =   300
  259.          Width           =   555
  260.       End
  261.       Begin VB.Label Label1 
  262.          Alignment       =   2  'Center
  263.          Caption         =   "Green"
  264.          Height          =   195
  265.          Index           =   4
  266.          Left            =   2220
  267.          TabIndex        =   21
  268.          Top             =   300
  269.          Width           =   555
  270.       End
  271.       Begin VB.Label Label1 
  272.          Alignment       =   2  'Center
  273.          Caption         =   "Red"
  274.          Height          =   195
  275.          Index           =   3
  276.          Left            =   1140
  277.          TabIndex        =   20
  278.          Top             =   300
  279.          Width           =   555
  280.       End
  281.       Begin VB.Label Label2 
  282.          Alignment       =   1  'Right Justify
  283.          Caption         =   "From:"
  284.          Height          =   195
  285.          Index           =   0
  286.          Left            =   240
  287.          TabIndex        =   19
  288.          Top             =   660
  289.          Width           =   495
  290.       End
  291.    End
  292.    Begin VB.Frame Frame2 
  293.       Caption         =   " Cell Colors "
  294.       Height          =   1155
  295.       Left            =   4560
  296.       TabIndex        =   7
  297.       Top             =   2400
  298.       Width           =   3375
  299.       Begin VB.TextBox txtColor 
  300.          Alignment       =   1  'Right Justify
  301.          Height          =   285
  302.          Index           =   0
  303.          Left            =   300
  304.          TabIndex        =   10
  305.          Text            =   "255"
  306.          Top             =   630
  307.          Width           =   495
  308.       End
  309.       Begin VB.TextBox txtColor 
  310.          Alignment       =   1  'Right Justify
  311.          Height          =   285
  312.          Index           =   1
  313.          Left            =   1320
  314.          TabIndex        =   9
  315.          Text            =   "255"
  316.          Top             =   630
  317.          Width           =   495
  318.       End
  319.       Begin VB.TextBox txtColor 
  320.          Alignment       =   1  'Right Justify
  321.          Height          =   285
  322.          Index           =   2
  323.          Left            =   2340
  324.          TabIndex        =   8
  325.          Text            =   "255"
  326.          Top             =   630
  327.          Width           =   495
  328.       End
  329.       Begin VB.Label Label1 
  330.          Alignment       =   2  'Center
  331.          Caption         =   "Red"
  332.          Height          =   195
  333.          Index           =   0
  334.          Left            =   300
  335.          TabIndex        =   16
  336.          Top             =   360
  337.          Width           =   555
  338.       End
  339.       Begin VB.Label Label1 
  340.          Alignment       =   2  'Center
  341.          Caption         =   "Green"
  342.          Height          =   195
  343.          Index           =   1
  344.          Left            =   1320
  345.          TabIndex        =   15
  346.          Top             =   360
  347.          Width           =   555
  348.       End
  349.       Begin VB.Label Label1 
  350.          Alignment       =   2  'Center
  351.          Caption         =   "Blue"
  352.          Height          =   195
  353.          Index           =   2
  354.          Left            =   2340
  355.          TabIndex        =   14
  356.          Top             =   360
  357.          Width           =   555
  358.       End
  359.       Begin Spin.SpinButton spnColor 
  360.          Height          =   345
  361.          Index           =   0
  362.          Left            =   840
  363.          TabIndex        =   13
  364.          Top             =   600
  365.          Width           =   225
  366.          _Version        =   65536
  367.          _ExtentX        =   397
  368.          _ExtentY        =   609
  369.          _StockProps     =   73
  370.          Delay           =   100
  371.          ShadowThickness =   1
  372.          TdThickness     =   1
  373.       End
  374.       Begin Spin.SpinButton spnColor 
  375.          Height          =   345
  376.          Index           =   1
  377.          Left            =   1860
  378.          TabIndex        =   12
  379.          Top             =   600
  380.          Width           =   225
  381.          _Version        =   65536
  382.          _ExtentX        =   397
  383.          _ExtentY        =   609
  384.          _StockProps     =   73
  385.          Delay           =   100
  386.          ShadowThickness =   1
  387.          TdThickness     =   1
  388.       End
  389.       Begin Spin.SpinButton spnColor 
  390.          Height          =   345
  391.          Index           =   2
  392.          Left            =   2880
  393.          TabIndex        =   11
  394.          Top             =   600
  395.          Width           =   225
  396.          _Version        =   65536
  397.          _ExtentX        =   397
  398.          _ExtentY        =   609
  399.          _StockProps     =   73
  400.          Delay           =   100
  401.          ShadowThickness =   1
  402.          TdThickness     =   1
  403.       End
  404.    End
  405.    Begin VB.Frame Frame1 
  406.       Caption         =   " Display "
  407.       Height          =   1155
  408.       Left            =   4560
  409.       TabIndex        =   2
  410.       Top             =   3660
  411.       Width           =   3375
  412.       Begin VB.ComboBox cboPalette 
  413.          Height          =   300
  414.          ItemData        =   "format2.frx":044A
  415.          Left            =   1860
  416.          List            =   "format2.frx":044C
  417.          Style           =   2  'Dropdown List
  418.          TabIndex        =   17
  419.          Top             =   300
  420.          Width           =   1335
  421.       End
  422.       Begin VB.CommandButton cmdRefreshPalette 
  423.          Caption         =   "Refresh Palette"
  424.          Height          =   315
  425.          Left            =   1860
  426.          TabIndex        =   6
  427.          Top             =   720
  428.          Width           =   1335
  429.       End
  430.       Begin VB.OptionButton optDecimal 
  431.          Caption         =   "As Decimal"
  432.          Height          =   255
  433.          Left            =   540
  434.          TabIndex        =   4
  435.          Top             =   480
  436.          Value           =   -1  'True
  437.          Width           =   1155
  438.       End
  439.       Begin VB.OptionButton optHex 
  440.          Caption         =   "As Hex"
  441.          Height          =   195
  442.          Left            =   540
  443.          TabIndex        =   3
  444.          Top             =   780
  445.          Width           =   1035
  446.       End
  447.       Begin Threed.SSCheck chkShowNumbers 
  448.          Height          =   255
  449.          Left            =   240
  450.          TabIndex        =   5
  451.          Top             =   240
  452.          Width           =   1515
  453.          _Version        =   65536
  454.          _ExtentX        =   2672
  455.          _ExtentY        =   450
  456.          _StockProps     =   78
  457.          Caption         =   "Show Numbers"
  458.          Value           =   -1  'True
  459.       End
  460.    End
  461.    Begin VB.TextBox txtFileName 
  462.       Height          =   285
  463.       Left            =   8220
  464.       TabIndex        =   1
  465.       Text            =   "MyPalet1.txt"
  466.       Top             =   4320
  467.       Width           =   1215
  468.    End
  469.    Begin VB.CommandButton cmdSaveAs 
  470.       Caption         =   "Save As"
  471.       Height          =   345
  472.       Left            =   8220
  473.       TabIndex        =   0
  474.       Top             =   3840
  475.       Width           =   1215
  476.    End
  477.    Begin VCIF1Lib.F1Book F1Book1 
  478.       Height          =   2115
  479.       Left            =   60
  480.       TabIndex        =   24
  481.       Top             =   60
  482.       Width           =   9555
  483.       _version        =   65536
  484.       _extentx        =   16854
  485.       _extenty        =   3731
  486.       _stockprops     =   96
  487.       borderstyle     =   1
  488.       appname         =   ""
  489.       filename        =   "format2.frx":044E
  490.    End
  491. Attribute VB_Name = "Form1"
  492. Attribute VB_Creatable = False
  493. Attribute VB_Exposed = False
  494. '' Format2 - a portable palette generator for Formula One 3.0 OCX
  495. '' Description:
  496. ''    Allows you to view and alter a palette and then save the entries
  497. ''    as VB code that you can later load into a project as a module to
  498. ''    setup a custom palette. The palette is layed out as it appears in
  499. ''    the custom color combo boxes (as on the FormatPatternDlg).
  500. ''    The Formula One palette was designed with Excel compatibility in
  501. ''    mind. The Excel palette has several (8) entries that are duplicates
  502. ''    and can be improved upon for several situations. One is color
  503. ''    coordinating a First Impression Chart with Formula One patterns.
  504. ''    The Palette1 module was extracted from First Impression. Now that
  505. ''    live charts can easily be placed on a Workbook, you can format your
  506. ''    data to match chart series colors or even data point colors.
  507. ''    This project also illustrates how handy Formula One can be as a programming
  508. ''    aid. For instance, I constructed the code in the Palette1 module by
  509. ''    copying the RGB values from First Impression into columns A, B, and C
  510. ''    of a Formula One Workbook. In cell D1 I placed the formula
  511. ''       =".PaletteEntry(" & ROW() & ") = RGB(" & A1 & "," & B1 & "," C1 & ")"
  512. ''    and then copied that formula down to row 63. I then removed a couple
  513. ''    of colors since the First Impression palette has more entries than
  514. ''    the Formula One palette. This was simple since the palette entries
  515. ''    were automatically fixed up when the row was deleted. Next, cut and paste
  516. ''    into the VB code window which again saved much typing. Another way Formula
  517. ''    One is used is as a text formatter. When you save a file in this
  518. ''    project, the code is placed in Formula One and saved as a text file.
  519. ''    Why use this? Often it is hard to get just the right look for the finished
  520. ''    project. You want just the right colors and patterns for your formatting
  521. ''    and spend a lot of time getting that look. This doesn't have much to do
  522. ''    with the problem solving you are doing but in many cases is as important.
  523. ''    Often you will find colors that suit you and want to use them over.
  524. ''    This project provides a little different way of creating a palette but
  525. ''    more importantly, allows you to save your work and easily reuse it. This
  526. ''    allows you to spend more time on the important code - the code that solves
  527. ''    the problem. If you build a collection of these reusable modules, you can
  528. ''    leave a lot of the UI till the end and then easliy and quickly change it
  529. ''    to suit customer desires.
  530. Option Explicit
  531. Private Sub cboPalette_Click()
  532.    Select Case cboPalette.ListIndex
  533.       Case 0:
  534.          Call ChangeToPalette1(F1Book1)
  535.       Case 1:
  536.          Call ChangeToPalette2(F1Book1)
  537.       Case 2:
  538.          Call ChangeToPalette3(F1Book1)
  539.       Case 3:
  540.          Call ChangeToPalette4(F1Book1)
  541.       Case 4:
  542.          Call ChangeToPalette5(F1Book1)
  543.       Case 5:
  544.          Call ChangeToPalette6(F1Book1)
  545.       Case 6:
  546.          Call ChangeToPalette7(F1Book1)
  547.    End Select
  548.    Call cmdRefreshPalette_Click
  549. End Sub
  550. Private Sub chkShowNumbers_Click(Value As Integer)
  551.    optDecimal.Enabled = Value
  552.    optHex.Enabled = Value
  553.    Call cmdRefreshPalette_Click
  554. End Sub
  555. Private Sub cmdGenPalette_Click()
  556. '' Uses settings in the Generate Palette Frame to set the
  557. '' Formula One palette. First two entries are always
  558. '' Black and white.
  559.    Const kLINEAR = 0
  560.    Const kLOG = 1
  561.    Const kILOG = 2
  562.    Const kBELL = 3
  563.    Dim rmin%, rmax%, gmin%, gmax%, bmin%, bmax%
  564.    Dim rval%, gval%, bval%
  565.    Dim rType%, gType%, bType%
  566.    Dim i%
  567.    rmin = Val(txtFrom(0).Text)
  568.    gmin = Val(txtFrom(1).Text)
  569.    bmin = Val(txtFrom(2).Text)
  570.    rmax = Val(TxtTo(0).Text)
  571.    gmax = Val(TxtTo(1).Text)
  572.    bmax = Val(TxtTo(2).Text)
  573.    If optRDelta(0).Value = True Then rType = kLINEAR
  574.    If optRDelta(1).Value = True Then rType = kLOG
  575.    If optRDelta(2).Value = True Then rType = kILOG
  576.    If optRDelta(3).Value = True Then rType = kBELL
  577.    If optGDelta(0).Value = True Then gType = kLINEAR
  578.    If optGDelta(1).Value = True Then gType = kLOG
  579.    If optGDelta(2).Value = True Then gType = kILOG
  580.    If optGDelta(3).Value = True Then gType = kBELL
  581.    If optBDelta(0).Value = True Then bType = kLINEAR
  582.    If optBDelta(1).Value = True Then bType = kLOG
  583.    If optBDelta(2).Value = True Then bType = kILOG
  584.    If optBDelta(3).Value = True Then bType = kBELL
  585.    With F1Book1
  586.       .PaletteEntry(1) = 0
  587.       .PaletteEntry(2) = RGB(255, 255, 255)
  588.       For i = 3 To 56
  589.          Select Case rType
  590.             Case kLINEAR:
  591.                rval = ((i / 56) * (rmax - rmin)) + rmin
  592.             Case kLOG:
  593.                rval = ((Log((i / 56) * 4)) * (rmax - rmin)) + rmin
  594.             Case kILOG:
  595.                rval = ((1 / (Log((i / 56) * 35))) * (rmax - rmin)) + rmin
  596.             Case kBELL:
  597.                rval = (Sin((i / 56) * 3.14) * (rmax - rmin)) + rmin
  598.          End Select
  599.          
  600.          Select Case gType
  601.             Case kLINEAR:
  602.                gval = ((i / 56) * (gmax - gmin)) + gmin
  603.             Case kLOG:
  604.                gval = ((Log((i / 56) * 4)) * (gmax - gmin)) + gmin
  605.             Case kILOG:
  606.                gval = ((1 / (Log((i / 56) * 35))) * (gmax - gmin)) + gmin
  607.          End Select
  608.          
  609.          Select Case bType
  610.             Case kLINEAR:
  611.                bval = ((i / 56) * (bmax - bmin)) + bmin
  612.             Case kLOG:
  613.                bval = ((Log((i / 56) * 4)) * (bmax - bmin)) + bmin
  614.             Case kILOG:
  615.                bval = ((1 / (Log((i / 56) * 35))) * (bmax - bmin)) + bmin
  616.          End Select
  617.          
  618.          .PaletteEntry(i) = RGB(Abs(rval), Abs(gval), Abs(bval))
  619.       Next i
  620.       
  621.    End With
  622.    Call cmdRefreshPalette_Click
  623. End Sub
  624. Private Sub cmdRefreshPalette_Click()
  625.    Dim i&, j&
  626.    With F1Book1
  627.       If chkShowNumbers.Value = False Then .ClearRange 1, 1, 7, 8, F1ClearAll
  628.       For j = 1 To 8
  629.          For i = 1 To 7
  630.             .SetSelection i, j, i, j
  631.             .SetPattern 1, .PaletteEntry(j + ((i - 1) * 8)), 0
  632.             If chkShowNumbers.Value = True Then
  633.                If optDecimal.Value = True Then
  634.                   .NumberRC(i, j) = .PaletteEntry(j + ((i - 1) * 8))
  635.                Else
  636.                   .TextRC(i, j) = Hex(.PaletteEntry(j + ((i - 1) * 8)))
  637.                End If
  638.             End If
  639.          Next i
  640.       Next j
  641.    End With
  642. End Sub
  643. Private Sub cmdSaveAs_Click()
  644. '' Formula One will not refresh the screen until we exit
  645. '' this procedure so we will write on it, save the file
  646. '' and then refresh the palette. Error checking is left
  647. '' as an exercise to the reader. The code uses numbers
  648. '' instead of the RGB function for speed. You can always
  649. '' add your saved palette back into this project to edit
  650. '' later.
  651.    On Error GoTo FileWriteError
  652.    Dim i&
  653.    With F1Book1
  654.       .ClearRange -1, -1, -1, -1, F1ClearAll
  655.       .TextRC(1, 1) = "Option Explicit"
  656.       .TextRC(3, 1) = "Sub " & Left$(txtFileName.Text, Len(txtFileName.Text) - 4) & "()"
  657.       .TextRC(5, 2) = "With F1Book1"
  658.       For i = 1 To 56
  659.          .TextRC(i + 6, 3) = ".PaletteEntry(" & i & ") = " & .PaletteEntry(i)
  660.       Next i
  661.       .TextRC(64, 2) = "End With"
  662.       .TextRC(65, 1) = "End Sub"
  663.       .Write App.Path & "\" & txtFileName.Text, F1FileTabbedText
  664.       '' Now set right alignment so the hex numbers look good
  665.       .SetSelection -1, -1, -1, -1
  666.       .SetAlignment F1HAlignRight, False, F1VAlignBottom, 0
  667.       .Selection = "A1"
  668.    End With
  669.    Call cmdRefreshPalette_Click
  670.    Exit Sub
  671. FileWriteError:
  672.    MsgBox Error
  673. End Sub
  674. Private Sub optHex_Click()
  675.    Call cmdRefreshPalette_Click
  676. End Sub
  677. Private Sub F1Book1_Click(ByVal nRow As Long, ByVal nCol As Long)
  678. '' Gets the palette entry associated with a cell, cracks it
  679. '' into RGB and puts it in the color text boxes
  680.    Dim r%, g%, b%, color&
  681.    If nRow > 0 And nCol > 0 Then    ' Ignore the col and row hdr clicks
  682.       color = F1Book1.PaletteEntry(nCol + ((nRow - 1) * 8))
  683.       Call CrackColor(color, r, g, b)
  684.       txtColor(0).Text = Str$(r)
  685.       txtColor(1).Text = Str$(g)
  686.       txtColor(2).Text = Str$(b)
  687.    End If
  688. End Sub
  689. Private Sub Form_Load()
  690.    F1Book1.Width = 9540
  691.    F1Book1.Height = 2070
  692.    Call cmdRefreshPalette_Click
  693.    cboPalette.AddItem "First Impression"
  694.    cboPalette.AddItem "Ochres"
  695.    cboPalette.AddItem "Yellow-Greens"
  696.    cboPalette.AddItem "Magentas"
  697.    cboPalette.AddItem "Blues"
  698.    cboPalette.AddItem "Cyan-Greens"
  699.    cboPalette.AddItem "Cyan-Blues"
  700. End Sub
  701. Sub CrackColor(color&, r%, g%, b%)
  702. '' Breaks a long color into its component parts and returns
  703. '' in r, g, and b. Note that the ColorRef stores the color
  704. '' in 3 low order bytes as BGR. The hex function does not
  705. '' pad with zeroes so we use a select.
  706.    Dim colorStr$, rStr$, gStr$, bStr$
  707.    Let colorStr = Hex(color)
  708.    Select Case Len(colorStr)
  709.       Case 1, 2:
  710.          r = Val("&H" & colorStr)
  711.          g = 0
  712.          b = 0
  713.       Case 3:
  714.          r = Val("&H" & Right$(colorStr, 2))
  715.          g = Val("&H" & Left$(colorStr, 1))
  716.          b = 0
  717.       Case 4:
  718.          r = Val("&H" & Right$(colorStr, 2))
  719.          g = Val("&H" & Left$(colorStr, 2))
  720.          b = 0
  721.       Case 5:
  722.          r = Val("&H" & Right$(colorStr, 2))
  723.          g = Val("&H" & Mid$(colorStr, 2, 2))
  724.          b = Val("&H" & Left$(colorStr, 1))
  725.       Case 6:
  726.          r = Val("&H" & Right$(colorStr, 2))
  727.          g = Val("&H" & Mid$(colorStr, 3, 2))
  728.          b = Val("&H" & Left$(colorStr, 2))
  729.    End Select
  730. End Sub
  731. Private Sub mnuCopy_Click()
  732.    F1Book1.Write App.Path & "\foo.txt", F1FileExcel5
  733. End Sub
  734. Private Sub spnColor_SpinDown(Index As Integer)
  735. '' Decrements the text box value and applies the new
  736. '' color to the palette entry corresponding to the selected
  737. '' cell in the worksheet. Decimals will appear to jump
  738. '' wildly. Use Hex view if you want them to increment
  739. '' smoothly.
  740.    Dim num%
  741.    num = Val(txtColor(Index).Text) - 1
  742.    If num > -1 Then
  743.       txtColor(Index).Text = Str$(num)
  744.       Call SetColor
  745.    End If
  746. End Sub
  747. Private Sub spnColor_SpinUp(Index As Integer)
  748. '' Increments the text box value and applies the new
  749. '' color to the palette entry corresponding to the selected
  750. '' cell in the worksheet. Decimals will appear to jump
  751. '' wildly. Use Hex view if you want them to increment
  752. '' smoothly.
  753.    Dim num%
  754.    num = Val(txtColor(Index).Text) + 1
  755.    If num < 256 Then
  756.       txtColor(Index).Text = Str$(num)
  757.       Call SetColor
  758.    End If
  759. End Sub
  760. Sub SetColor()
  761.    Dim pNum&
  762.    With F1Book1
  763.       pNum = .SelStartCol + ((.SelStartRow - 1) * 8)
  764.       .PaletteEntry(pNum) = RGB(Val(txtColor(0).Text), Val(txtColor(1).Text), Val(txtColor(2).Text))
  765.       .SetPattern 1, .PaletteEntry(pNum), 0
  766.       If chkShowNumbers.Value = True Then
  767.          If optDecimal.Value = True Then
  768.             .Number = .PaletteEntry(pNum)
  769.          Else
  770.             .Text = Hex(.PaletteEntry(pNum))
  771.          End If
  772.       End If
  773.    End With
  774.       
  775. End Sub
  776. Private Sub txtColor_KeyPress(Index As Integer, KeyAscii As Integer)
  777. '' If the user types a value in the text box and then hits return
  778. '' we will set the palette entry. If they enter an invalid number
  779. '' we set it to zero. This is a programmer's tool so we can be terse.
  780.    Dim newNum%
  781.    If KeyAscii = 13 Then
  782.       newNum = Val(txtColor(Index).Text)
  783.       If newNum > -1 And newNum < 256 Then
  784.          txtColor(Index).Text = Str$(newNum)
  785.       Else
  786.          txtColor(Index).Text = 0
  787.       End If
  788.       Call SetColor
  789.    End If
  790. End Sub
  791. Private Sub txtFrom_KeyPress(Index As Integer, KeyAscii As Integer)
  792.    If KeyAscii = 13 Then
  793.       If Val(txtFrom(Index).Text) < 0 Or Val(txtFrom(Index).Text) > 255 Then
  794.          txtFrom(Index).Text = "0"
  795.       End If
  796.    End If
  797. End Sub
  798. Private Sub TxtTo_KeyPress(Index As Integer, KeyAscii As Integer)
  799.    If KeyAscii = 13 Then
  800.       If Val(TxtTo(Index).Text) < 0 Or Val(TxtTo(Index).Text) > 255 Then
  801.          TxtTo(Index).Text = "0"
  802.       End If
  803.    End If
  804. End Sub
  805.